represents point or position, velocity and scale. Note! Angular velocity can not be represented by this type, it should be represented by Transform. It is a class inheriting numpy.ndarray, so it is also ndarray.
from py3d import Vector3
Vector3()
Welcome to py3d world, please visit https://tumiz.github.io/scenario/ for more information
Vector3([0., 0., 0.])
Vector3(x=1.2)
Vector3([1.2, 0. , 0. ])
Vector3(x=1, y=3, z=-2.4)
Vector3([ 1. , 3. , -2.4])
Vector3(x=1, y=3, z=-2.4, n=(2,))
Vector3([[ 1. , 3. , -2.4],
[ 1. , 3. , -2.4]])
Get unit vector
Vector3().U
Vector3([0., 0., 0.])
Get length
Vector3([1,2,3]).L
array([3.74165739])
Vector3([
[1,2,3],
[4,5,6]]).L
array([[3.74165739],
[8.77496439]])
Get a random vector
Vector3.Rand()
Vector3([0.89080463, 0.32286414, 0.63777564])
Get a random vector list
Vector3.Rand(3)
Vector3([[0.00387297, 0.02409548, 0.39490203],
[0.01154913, 0.05903717, 0.44225386],
[0.81956006, 0.51993048, 0.3481314 ]])
Cross product
Vector3(x=3).cross(Vector3(y=2))
Vector3([0., 0., 6.])
Display points
import plotly.express as px
p = Vector3.Rand(10).cumsum(axis=0)
fig = px.scatter_3d(x=p.x, y=p.y, z=p.z)
fig.show()
Use Vector3 as 2d vector
p=(Vector3.Rand(100)-0.5).U
fig = px.scatter_3d(x=p.x, y=p.y, z=p.z)
fig.show()